package com.compass.doctor.ui.chat.attachment

import com.compass.doctor.R

import com.compass.framework.constant.SUBSCRIBE_CODE
import com.compass.framework.utils.getStringFromResource
import com.netease.yunxin.kit.corekit.im.custom.CustomAttachment
import org.json.JSONObject

/**
 * Description： 预问诊自定义消息
 * Date:2024/3/2 9:23
 */
class PreConsultationAttachment : CustomAttachment(SUBSCRIBE_CODE) {
    private var patientName: String? = null //患者姓名
    private var patientAge: String? = null //患者年龄
    private var sex: String? = null //患者性别
    private var id: String? = null //预问诊单id
    private var patientAvatar: String? = null//头像
    private var mainSuit: String? = null//主诉
    private var historyIllness: String? = null//现病史
    private var previousHistory: String? = null//既往史
    private var individualHis: String? = null//个人史
    private var allergicHistory: String? = null//过敏史


    //重写数据解析方法，这里面数据以JSONObject格式进行传输，所以您可以制定自己的数据格式。
    //这个示例表示，自定义数据格式为{"customer_message_key":"我是一个自定义消息"}
    override fun packData(): JSONObject {
        var data = JSONObject()
        data.put("patientName", patientName)
        data.put("patientAge", patientAge)
        data.put("sex", sex)
        data.put("mainSuit", mainSuit)
        data.put("id", id)
        data.put("patientAvatar", patientAvatar)
        data.put("historyIllness", historyIllness)
        data.put("previousHistory", previousHistory)
        data.put("individualHis", individualHis)
        data.put("allergicHistory", allergicHistory)
        return data
    }


    override fun parseData(jsonObject: JSONObject?) {
        // 从接收到的消息内容中解析您的数据
        jsonObject?.let {
            this.patientName = jsonObject.getString("patientName")
            this.patientAge = jsonObject.getString("patientAge")
            this.sex = jsonObject.getString("sex")
            this.mainSuit = jsonObject.getString("mainSuit")
            this.id = jsonObject.getString("id")
            this.patientAvatar = jsonObject.getString("patientAvatar")
            this.historyIllness = jsonObject.getString("historyIllness")
            this.previousHistory = jsonObject.getString("previousHistory")
            this.individualHis = jsonObject.getString("individualHis")
            this.allergicHistory = jsonObject.getString("allergicHistory")

        }

    }


    /**
     * 设置问诊单数据
     */
    fun setConsultationData(patientName: String, age: String, mainSuit: String, sex: String,id:String) {
        this.patientName = patientName;
        this.patientAge = age;
        this.mainSuit = mainSuit;
        this.sex = sex;
        this.id = id;

    }


    override fun getContent(): String? {
        return getStringFromResource(R.string.attachment_subscribe_msg)
    }


    fun getPatientName(): String? {
        return patientName;
    }


    fun getPatientAge(): String {
        patientAge?.let {
            return it
        }?:kotlin.run {
            return "0岁"
        }
    }

    fun getSex(): String? {
        return sex;
    }

    fun getMainSuit(): String? {
        return mainSuit;
    }

    fun getPatientId(): String? {
        return id;
    }

    fun getPatientAvatar(): String? {
        return patientAvatar;
    }

    fun getHistoryIllness(): String? {
        if (historyIllness.isNullOrEmpty()){
            return "暂无现病史"
        }
        return historyIllness;
    }

    fun getPreviousHistory(): String? {
        if (previousHistory.isNullOrEmpty()){
            return "暂无既往史"
        }
        return previousHistory;
    }

    fun getIndividualHis():String?{
        if (individualHis.isNullOrEmpty()){
            return "暂无个人史"
        }
        return individualHis;
    }

    fun getAllergicHistory():String?{
        if (allergicHistory.isNullOrEmpty()){
            return "暂无过敏史"
        }
        return allergicHistory;
    }
}